package com.jinglin.controller;

import com.jinglin.pojo.ArticleCate;
import com.jinglin.service.ArticleCateService;
import com.jinglin.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ArticleCateController {
    @Autowired
    private ArticleCateService articleCateService;
    // 获取分类列表
    @GetMapping("/my/cate/list")
    public Result getArticleCateList() {
        List<ArticleCate> list = articleCateService.list();
        System.out.println(list);
        return new Result(list,0,"获取文章分类列表成功！！！");
    }
    // 新增分类
    @PostMapping("/my/cate/add")
    public Result addArticleCate(@RequestBody ArticleCate articleCate){
        System.out.println(articleCate);
        articleCateService.save(articleCate);
        return Result.success("新增分类成功！！！");
    }
    // 删除分类
    @DeleteMapping("/my/cate/del")
    public Result deleteArticleCate(@RequestParam("id") String id){
        articleCateService.removeById(id);
        return Result.success("删除成功");
    }
    // 编辑分类
    @PutMapping("/my/cate/info")
    public Result updateCateInfo(@RequestBody ArticleCate articleCate){
/*        LambdaUpdateWrapper<ArticleCate> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ArticleCate::getId, articleCate.getId());*/
        articleCateService.update(articleCate,null);
        return Result.success("更新成功！！！");
    }
    // 获取文章分类详情
    @GetMapping("/my/cate/info")
    public Result getArticleCateInfo(@RequestParam("id") String id) {
        ArticleCate cate = articleCateService.getById(id);
        return Result.success(cate);
    }

}
